package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.entitry.Category;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 张伟奇
 * @Date 2021/7/14 3:46
 * @description
 * @Version 1.0
 **/
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    public List<CategoryDTO> listCategoryByPid(Long pid){

        List<Category> listCategoryByPidList
                = categoryMapper.selectList(new QueryWrapper<Category>().eq("parent_id", pid));

        return CategoryDTO.converEntity(listCategoryByPidList);
    }

    @Override
    public List<CategoryDTO> listCategorySoftById(Integer id) {

        List<Category> categoryList = categoryMapper.selectList(new QueryWrapper<Category>().eq("id", id));
        return CategoryDTO.converEntity(categoryList);
    }

    @Override
    public List<CategoryDTO> listCategorySoftByIds(List<Integer> ids) {

        List selectBatchIds = categoryMapper.selectBatchIds(ids);
        return CategoryDTO.converEntity(selectBatchIds);
    }

    @Override
    public List<CategoryDTO> findCategoryByBrandId(Integer id) {
        List<Integer> categoryIdByBrand = categoryMapper.findCategoryIdByBrand(id);
        List<CategoryDTO> categoryDTOS = this.listCategorySoftByIds(categoryIdByBrand);
        return categoryDTOS;
    }


}
